package servlet.admin;

import service.AdoptService;
import service.Impl.AdoptServiceImpl;
import org.json.JSONObject;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(urlPatterns = "/admin/Adoptdisagree")
public class AdoptDisagreeServlet extends HttpServlet {
    private AdoptService adoptService = new AdoptServiceImpl();

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        resp.setContentType("application/json;charset=UTF-8");
        resp.setCharacterEncoding("UTF-8");
        String idParam = req.getParameter("id");
        int id = Integer.parseInt(idParam);
        boolean success = adoptService.disagreeAdopt(id);
        JSONObject jsonResponse = new JSONObject();
        jsonResponse.put("success", success);
        if (!success) {
            jsonResponse.put("error", "错误！");
        }
        resp.getWriter().write(jsonResponse.toString());

    }
}